package com.bree.erp.entity;

import java.util.Map;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Id;
import javax.persistence.MapKeyColumn;
import javax.persistence.MapKeyEnumerated;
import javax.persistence.NamedQuery;

@NamedQuery(name = Warehouse.QUERY_SELECT_ALL_WAREHOUSE,
	query = "SELECT w FROM Warehouse w")
@Entity
public class Warehouse implements CrudId<String> {
	
	public static final String QUERY_SELECT_ALL_WAREHOUSE = "selectAllWarehouse";
	
	@Id
	private String id;
	
	private String name;
	
	@ElementCollection
	@CollectionTable(name="WAREHOUSE_PHONE")
	@MapKeyEnumerated(EnumType.STRING)
	@MapKeyColumn(name="PHONE_TYPE")
	@Column(name="PHONE_NUM")
	private Map<PhoneType, String> phoneNumbers;
	
	@Embedded
	private Address address;
	
	
	public String getLandline() {
		return phoneNumbers == null ? null : phoneNumbers.get(PhoneType.LANDLINE);
	}
	public String getMobile() {
		return phoneNumbers == null ? null : phoneNumbers.get(PhoneType.MOBILE);
	}
	public String getFax() {
		return phoneNumbers == null ? null : phoneNumbers.get(PhoneType.FAX);
	}
	public String getEmail() {
		return phoneNumbers == null ? null : phoneNumbers.get(PhoneType.EMAIL);
	}
	
	@Override
	public boolean equals(Object object) {
		if(object instanceof Warehouse) {
			Warehouse that = (Warehouse) object;
			return this.id != null && this.id.equals(that.id);
		}
		
		return false;
	}
	
	@Override
	public int hashCode() {
		return this.id == null ? 0 : this.id.hashCode();
	}


	/**
	 * @return the phoneNumbers
	 */
	public Map<PhoneType, String> getPhoneNumbers() {
		return phoneNumbers;
	}

	/**
	 * @param phoneNumbers the phoneNumbers to set
	 */
	public void setPhoneNumbers(Map<PhoneType, String> phoneNumbers) {
		this.phoneNumbers = phoneNumbers;
	}

	/**
	 * @return the address
	 */
	public Address getAddress() {
		return address;
	}

	/**
	 * @param address the address to set
	 */
	public void setAddress(Address address) {
		this.address = address;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}
	
	
}
